package com_djm_2025_05_26.OOP.CodeBlocks;

public class Student {
    //定义内方法体外部，类体内部的代码块为构造代码块，主要用于成员变量的初始化
    private String name = "铠";

    private int age = 17;

    private static String className = "118-c++";

    static {
        System.out.println("静态代码块执行!");
        Student.className = "118";
    }

    {
        System.out.println("构造代码块执行了");
        System.out.println(this.name);
        System.out.println(this.age);
        System.out.println(className);
        this.name = "关羽";
        this.age = 22;
        className = "118-Java";
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public static String getClassName() {
        return className;
    }

    public static void setClassName(String className) {
        Student.className = className;
    }

    public Student(){
        System.out.println("无参构造方法执行");
    }

    public static void main(String[] args) {
        //结论：构造代码块在构造方法之前执行,静态代码块在构造代码块之前执行
        Student stu = new Student();

        System.out.println(stu.name);
        System.out.println(stu.age);
        System.out.println(Student.className);

    }
}
